package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.utils.JwtUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试类
 *
 * @author zhangkaiqi
 * @date 2021/8/6 14:19:11
 */
@RestController
public class LoginController {
    @PostMapping("/")
    public String login(@RequestBody User user) {
        if (user == null) {
            return "用户名和密码不能为空";
        }
        if ("admin".equals(user.getPassword()) || "admin".equals(user.getUsername())) {
            String token = JwtUtils.generateJsonWebToken(user);
            System.out.println("Token为" + token);
        }
        return "登录成功";
    }
}
